﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security;
using System.Security.Cryptography.X509Certificates;

namespace TestWebApplication
{
    public class CertStore
    {
        public static X509Certificate2Collection getAllCerts()
        {
            X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            store.Open(OpenFlags.IncludeArchived);
            X509Certificate2Collection certsCollection = store.Certificates;

            return certsCollection;
        }

        public static X509Certificate2 getCert(string name)
        {
            X509Certificate2Collection certsCollection = getAllCerts();

            foreach (X509Certificate2 cert in certsCollection)
            {
                string currentname = cert.GetNameInfo(X509NameType.SimpleName, false);
                if (name.Equals(currentname)) return cert;

            }

            return null;
        }

        /*public static WebSeviceManager GetWebServiceManager()
        {
            WebSeviceManager webServiceManager = (WebSeviceManager)HttpContext.Current.Cache["WebSeviceManager"];
            if (webServiceManager == null)
            {
                webServiceManager = new WebSeviceManager();
                HttpContext.Current.Cache["WebSeviceManager"] = webServiceManager;
            }

            return webServiceManager;
        }*/

    }
}